```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入解析HashMap与HashSet</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .prose {
            max-width: 65ch;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4.5rem;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #4f46e5;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.25rem;
            overflow-x: auto;
        }
        .keyword {
            color: #60a5fa;
        }
        .type {
            color: #86efac;
        }
        .string {
            color: #fbbf24;
        }
        .comment {
            color: #9ca3af;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 40%;
            background-color: rgba(79, 70, 229, 0.2);
            z-index: -1;
            transition: all 0.2s ease;
        }
        .highlight:hover:after {
            height: 60%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative bg-gradient-to-r from-indigo-500 to-purple-600 text-white py-20 md:py-32 px-4 sm:px-6 lg:px-8">
        <div class="max-w-7xl mx-auto text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 serif tracking-tight">
                深入解析<span class="highlight">HashMap</span>与<span class="highlight">HashSet</span>
            </h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90">
                Java集合框架中的哈希表实现原理与最佳实践
            </p>
            <div class="mt-10 flex justify-center">
                <div class="inline-flex rounded-md shadow">
                    <a href="#hashmap-design" class="inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-indigo-600 bg-white hover:bg-indigo-50 transition duration-150">
                        <i class="fas fa-book-open mr-2"></i> 开始阅读
                    </a>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Intro Section -->
        <section class="mb-16">
            <div class="prose mx-auto">
                <p class="drop-cap">
                    <span class="serif">H</span>ashMap 和 HashSet 是 Java 集合框架中常用的集合类，它们的底层实现是基于哈希表（Hash Table）数据结构。虽然这两个类的目的不同，但它们的实现原理非常相似，尤其是 HashSet 在内部实际上是通过 HashMap 来实现的。
                </p>
            </div>
        </section>

        <!-- Design Principles Section -->
        <section id="hashmap-design" class="mb-16">
            <div class="grid md:grid-cols-2 gap-8">
                <!-- HashMap Card -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                    <div class="bg-indigo-600 p-6">
                        <div class="flex items-center">
                            <div class="flex-shrink-0 bg-white p-2 rounded-md">
                                <i class="fas fa-map text-indigo-600 text-2xl"></i>
                            </div>
                            <h2 class="ml-4 text-white text-2xl font-bold serif">HashMap 设计原理</h2>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            <span class="font-semibold">HashMap</span> 是一个基于哈希表实现的 <span class="font-semibold">Map</span> 接口的实现类。它存储键值对（key-value），通过哈希算法计算出键的哈希值，然后使用该哈希值来确定键值对存储的位置。
                        </p>
                        <div class="bg-indigo-50 rounded-lg p-4 border-l-4 border-indigo-500">
                            <p class="text-indigo-800 font-medium">
                                <i class="fas fa-info-circle mr-2"></i> HashMap 的常见操作，如插入、查找、删除元素等，时间复杂度通常是 O(1)。
                            </p>
                        </div>
                    </div>
                </div>

                <!-- HashSet Card -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                    <div class="bg-purple-600 p-6">
                        <div class="flex items-center">
                            <div class="flex-shrink-0 bg-white p-2 rounded-md">
                                <i class="fas fa-layer-group text-purple-600 text-2xl"></i>
                            </div>
                            <h2 class="ml-4 text-white text-2xl font-bold serif">HashSet 设计原理</h2>
                        </div>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">
                            <span class="font-semibold">HashSet</span> 是一个基于 <span class="font-semibold">HashMap</span> 实现的 <span class="font-semibold">Set</span> 接口的实现类。HashSet 不允许重复元素，它将元素作为 HashMap 的键存储，所有元素的值都设置为一个固定的常量对象。
                        </p>
                        <div class="bg-purple-50 rounded-lg p-4 border-l-4 border-purple-500">
                            <p class="text-purple-800 font-medium">
                                <i class="fas fa-info-circle mr-2"></i> 通过 HashMap 来避免重复元素的存储。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Internal Structure Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="bg-gradient-to-r from-gray-800 to-gray-700 p-6">
                    <h2 class="text-white text-2xl font-bold serif">HashMap 的内部数据结构与初始化</h2>
                </div>
                <div class="p-6">
                    <p class="text-gray-700 mb-6">
                        HashMap 内部是通过数组和链表或红黑树来实现哈希表的。当发生哈希冲突时，多个键值对会被存储在同一个桶（bucket）中，最开始是通过链表来解决冲突。
                    </p>

                    <h3 class="text-xl font-semibold text-gray-800 mb-4 serif">初始化与容量管理</h3>
                    <div class="code-block mb-6">
                        <pre><code><span class="keyword">public class</span> <span class="type">HashMap</span>&lt;K, V&gt; <span class="keyword">extends</span> <span class="type">AbstractMap</span>&lt;K, V&gt; <span class="keyword">implements</span> <span class="type">Map</span>&lt;K, V&gt; {
    <span class="keyword">transient</span> <span class="type">Node</span>&lt;K, V&gt;[] table;  <span class="comment">// 哈希表的数组</span>
    <span class="keyword">private static final</span> <span class="type">int</span> DEFAULT_INITIAL_CAPACITY = <span class="number">1</span> &lt;&lt; <span class="number">4</span>;  <span class="comment">// 默认初始容量16</span>
    <span class="keyword">private static final</span> <span class="type">float</span> DEFAULT_LOAD_FACTOR = <span class="number">0.75f</span>;  <span class="comment">// 默认负载因子</span>
    <span class="keyword">private</span> <span class="type">int</span> size = <span class="number">0</span>;  <span class="comment">// 元素数量</span>
    <span class="keyword">private</span> <span class="type">int</span> threshold;  <span class="comment">// 扩容阈值</span>

    <span class="keyword">public</span> <span class="type">HashMap</span>(<span class="type">int</span> initialCapacity, <span class="type">float</span> loadFactor) {
        <span class="keyword">if</span> (initialCapacity &lt; <span class="number">0</span> || loadFactor &lt;= <span class="number">0</span>)
            <span class="keyword">throw new</span> <span class="type">IllegalArgumentException</span>();
        <span class="keyword">this</span>.threshold = thresholdFor(initialCapacity);
    }

    <span class="comment">// 计算扩容阈值</span>
    <span class="keyword">private static final</span> <span class="type">int</span> thresholdFor(<span class="type">int</span> capacity) {
        <span class="keyword">return</span> (<span class="type">int</span>) <span class="type">Math</span>.min(capacity * DEFAULT_LOAD_FACTOR, <span class="type">Integer</span>.MAX_VALUE);
    }
}</code></pre>
                    </div>

                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-2">
                                <div class="bg-indigo-100 p-2 rounded-full mr-3">
                                    <i class="fas fa-table text-indigo-600"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800">table 数组</h4>
                            </div>
                            <p class="text-gray-600 text-sm">存储键值对的数组，每个元素是一个链表或红黑树的头节点</p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-2">
                                <div class="bg-purple-100 p-2 rounded-full mr-3">
                                    <i class="fas fa-expand text-purple-600"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800">默认容量</h4>
                            </div>
                            <p class="text-gray-600 text-sm">初始容量为16，负载因子为0.75</p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <div class="flex items-center mb-2">
                                <div class="bg-amber-100 p-2 rounded-full mr-3">
                                    <i class="fas fa-balance-scale-right text-amber-600"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800">扩容阈值</h4>
                            </div>
                            <p class="text-gray-600 text-sm">当元素数量超过容量的75%时，哈希表会自动扩容</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Insertion Implementation Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="bg-gradient-to-r from-indigo-700 to-blue-600 p-6">
                    <h2 class="text-white text-2xl font-bold serif">插入元素的实现</h2>
                </div>
                <div class="p-6">
                    <p class="text-gray-700 mb-6">
                        当我们通过 <code class="bg-gray-100 px-1 py-0.5 rounded">put(K key, V value)</code> 方法向 HashMap 中插入元素时，首先会根据 key 计算其哈希值，然后通过哈希值定位到哈希表的索引位置。如果该位置没有元素，则直接插入；如果该位置有元素（发生冲突），则采用链表法将新节点插入到链表中。
                    </p>

                    <div class="code-block mb-6">
                        <pre><code><span class="keyword">public</span> V put(K key, V value) {
    <span class="type">int</span> hash = hash(key);  <span class="comment">// 计算 key 的哈希值</span>
    <span class="type">int</span> index = indexFor(hash, table.length);  <span class="comment">// 计算索引位置</span>
    <span class="keyword">for</span> (<span class="type">Node</span>&lt;K, V&gt; e = table[index]; e != <span class="keyword">null</span>; e = e.next) {
        <span class="keyword">if</span> (e.hash == hash && (e.key == key || key.equals(e.key))) {
            V oldValue = e.value;
            e.value = value;  <span class="comment">// 更新 value</span>
            <span class="keyword">return</span> oldValue;
        }
    }
    addEntry(hash, key, value, index);  <span class="comment">// 插入新元素</span>
    <span class="keyword">return</span> <span class="keyword">null</span>;
}

<span class="comment">// 计算哈希值</span>
<span class="keyword">static final</span> <span class="type">int</span> hash(<span class="type">Object</span> key) {
    <span class="type">int</span> h = key.hashCode();
    <span class="keyword">return</span> (h ^ (h &gt;&gt;&gt; <span class="number">16</span>)) & <span class="number">0x7fffffff</span>;  <span class="comment">// 高16位和低16位进行异或运算</span>
}

<span class="comment">// 计算元素在哈希表中的位置</span>
<span class="keyword">private static</span> <span class="type">int</span> indexFor(<span class="type">int</span> hash, <span class="type">int</span> length) {
    <span class="keyword">return</span> hash & (length - <span class="number">1</span>);  <span class="comment">// 通过掩码计算数组的索引</span>
}

<span class="keyword">private</span> <span class="type">void</span> addEntry(<span class="type">int</span> hash, K key, V value, <span class="type">int</span> bucketIndex) {
    <span class="type">Node</span>&lt;K, V&gt; e = table[bucketIndex];
    table[bucketIndex] = <span class="keyword">new</span> <span class="type">Node</span>&lt;&gt;(hash, key, value, e);  <span class="comment">// 将新节点插入到链表头</span>
    <span class="keyword">if</span> (size++ &gt;= threshold)  <span class="comment">// 当元素数量超过阈值时，进行扩容</span>
        resize(<span class="number">2</span> * table.length);
}</code></pre>
                    </div>

                    <div class="bg-blue-50 rounded-lg p-4 border-l-4 border-blue-500 mb-6">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-list-ol mr-2"></i> 插入过程
                        </h4>
                        <ol class="list-decimal pl-5 space-y-2 text-blue-800">
                            <li>计算 <code class="bg-blue-100 px-1 py-0.5 rounded">key</code> 的哈希值</li>
                            <li>根据哈希值计算索引位置</li>
                            <li>如果该位置没有元素，直接插入新节点</li>
                            <li>如果该位置已有元素（哈希冲突），则使用链表法解决冲突</li>
                            <li>如果插入后的元素数量超过阈值，进行扩容</li>
                        </ol>
                    </div>

                    <div class="mermaid mb-6">
                        graph TD
                            A[调用put方法] --> B[计算key的哈希值]
                            B --> C[计算索引位置]
                            C --> D{位置是否为空?}
                            D -->|是| E[直接插入新节点]
                            D -->|否| F[遍历链表查找key]
                            F --> G{key是否存在?}
                            G -->|是| H[更新value]
                            G -->|否| I[链表头部插入新节点]
                            I --> J{是否超过阈值?}
                            J -->|是| K[扩容并重新哈希]
                    </div>
                </div>
            </div>
        </section>

        <!-- HashSet Implementation Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="bg-gradient-to-r from-purple-700 to-indigo-600 p-6">
                    <h2 class="text-white text-2xl font-bold serif">HashSet 的实现原理</h2>
                </div>
                <div class="p-6">
                    <p class="text-gray-700 mb-6">
                        HashSet 的底层实现其实是通过 HashMap 来实现的。每个 HashSet 中的元素都对应 HashMap 的一个键，而值则使用一个固定的常量对象（PRESENT）。因此，HashSet 中不允许重复元素，重复元素的插入会被 HashMap 的 put 方法自动拒绝。
                    </p>

                    <div class="code-block mb-6">
                        <pre><code><span class="keyword">public class</span> <span class="type">HashSet</span>&lt;E&gt; <span class="keyword">extends</span> <span class="type">AbstractSet</span>&lt;E&gt; <span class="keyword">implements</span> <span class="type">Set</span>&lt;E&gt;, <span class="type">Cloneable</span>, <span class="type">java.io.Serializable</span> {
    <span class="keyword">private transient</span> <span class="type">HashMap</span>&lt;E, <span class="type">Object</span>&gt; map;

    <span class="keyword">private static final</span> <span class="type">Object</span> PRESENT = <span class="keyword">new</span> <span class="type">Object</span>();

    <span class="keyword">public</span> <span class="type">HashSet</span>() {
        map = <span class="keyword">new</span> <span class="type">HashMap</span>&lt;&gt;();
    }

    <span class="keyword">public</span> <span class="type">boolean</span> add(E e) {
        <span class="keyword">return</span> map.put(e, PRESENT) == <span class="keyword">null</span>;  <span class="comment">// 利用 HashMap 的 put 方法插入元素</span>
    }

    <span class="keyword">public</span> <span class="type">boolean</span> contains(<span class="type">Object</span> o) {
        <span class="keyword">return</span> map.containsKey(o);  <span class="comment">// 判断元素是否存在</span>
    }

    <span class="keyword">public</span> <span class="type">boolean</span> remove(<span class="type">Object</span> o) {
        <span class="keyword">return</span> map.remove(o) == PRESENT;  <span class="comment">// 移除元素</span>
    }
}</code></pre>
                    </div>

                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-purple-50 rounded-lg p-4 border-l-4 border-purple-500">
                            <h4 class="font-semibold text-purple-800 mb-2 flex items-center">
                                <i class="fas fa-plus-circle mr-2"></i> HashSet 插入过程
                            </h4>
                            <ol class="list-decimal pl-5 space-y-2 text-purple-800">
                                <li>在 HashSet 中添加元素时，会调用 HashMap 的 <code class="bg-purple-100 px-1 py-0.5 rounded">put()</code> 方法</li>
                                <li>HashSet 利用 HashMap 存储元素</li>
                                <li>通过 PRESENT 常量表示 HashMap 中每个键对应的值</li>
                            </ol>
                        </div>
                        <div class="bg-indigo-50 rounded-lg p-4 border-l-4 border-indigo-500">
                            <h4 class="font-semibold text-indigo-800 mb-2 flex items-center">
                                <i class="fas fa-key mr-2"></i> 关键设计点
                            </h4>
                            <ul class="list-disc pl-5 space-y-2 text-indigo-800">
                                <li>所有元素作为 HashMap 的键存储</li>
                                <li>值使用统一的 PRESENT 对象节省空间</li>
                                <li>利用 HashMap 的去重特性实现 Set 接口</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Search and Delete Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="bg-gradient-to-r from-gray-800 to-gray-700 p-6">
                    <h2 class="text-white text-2xl font-bold serif">查找和删除操作</h2>
                </div>
                <div class="p-6">
                    <div class="grid md:grid-cols-2 gap-8">
                        <!-- HashMap Search -->
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4 serif">HashMap 查找</h3>
                            <p class="text-gray-700 mb-4">
                                HashMap 查找元素时，会根据 key 计算哈希值，定位到对应的桶，然后遍历桶中的链表，找到对应的键值对。
                            </p>
                            <div class="code-block">
                                <pre><code><span class="keyword">public</span> V get(<span class="type">Object</span> key) {
    <span class="type">int</span> hash = hash(key);
    <span class="type">int</span> index = indexFor(hash, table.length);
    <span class="keyword">for</span> (<span class="type">Node</span>&lt;K, V&gt; e = table[index]; e != <span class="keyword">null</span>; e = e.next) {
        <span class="keyword">if</span> (e.hash == hash && (e.key == key || key.equals(e.key))) {
            <span class="keyword">return</span> e.value;
        }
    }
    <span class="keyword">return</span> <span class="keyword">null</span>;
}</code></pre>
                            </div>
                        </div>
                        
                        <!-- HashMap Delete -->
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-4 serif">HashMap 删除</h3>
                            <p class="text-gray-700 mb-4">
                                删除操作和查找类似，首先根据 key 计算哈希值定位到桶，然后遍历链表查找要删除的节点。
                            </p>
                            <div class="code-block">
                                <pre><code><span class="keyword">public</span> V remove(<span class="type">Object</span> key) {
    <span class="type="int"> hash = hash(key);
    <span class="type">int</span> index = indexFor(hash, table.length);
    <span class="type">Node</span>&lt;K, V&gt; prev = <span class="keyword">null</span>;
    <span class="keyword">for</span> (<span class="type">Node</span>&lt;K, V&gt; e = table[index]; e != <span class="keyword">null</span>; e = e.next) {
        <span class="keyword">if</span> (e.hash == hash && (e.key == key || key.equals(e.key))) {
            <span class="keyword">if</span> (prev == <span class="keyword">null</span>)
                table[index] = e.next;
            <span class="keyword">else</span>
                prev.next = e.next;
            size--;
            <span class="keyword">return</span> e.value;
        }
        prev = e;
    }
    <span class="keyword">return</span> <span class="keyword">null</span>;
}</code></pre>
                            </div>
                        </div>
                    </div>

                    <div class="mt-8 bg-gray-50 rounded-lg p-4 border-l-4 border-gray-500">
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-exchange-alt mr-2"></i> HashSet 查找与删除
                        </h4>
                        <p class="text-gray-700">
                            HashSet 的查找和删除操作也是通过 HashMap 完成的，HashSet 直接调用 HashMap 的 <code class="bg-gray-100 px-1 py-0.5 rounded">containsKey()</code> 和 <code class="bg-gray-100 px-1 py-0.5 rounded">remove()</code> 方法。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Resize Mechanism Section -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="bg-gradient-to-r from-amber-600 to-amber-500 p-6">
                    <h2 class="text-white text-2xl font-bold serif">扩容机制</h2>
                </div>
                <div class="p-6">
                    <p class="text-gray-700 mb-6">
                        HashMap 和 HashSet 都有扩容机制，当哈希表的负载超过阈值时，会将容量翻倍。扩容操作的关键在于 <code class="bg-gray-100 px-1 py-0.5 rounded">resize()</code> 方法，它会创建一个新的更大的数组，并将旧数组的元素重新哈希到新数组中。
                    </p>

                    <div class="code-block mb-6">
                        <pre><code><span class="keyword">private</span> <span class="type">void</span> resize(<span class="type">int</span> newCapacity) {
    <span class="type">Node</span>&lt;K, V&gt;[] newTable = <span class="keyword">new</span> <span class="type">Node</span>[newCapacity];
    transfer(newTable);
    table = newTable;
    threshold = thresholdFor(newCapacity);
}

<span class="keyword">private</span> <span class="type">void</span> transfer(<span class="type">Node</span>&lt;K, V&gt;[] newTable) {
    <span class="keyword">for</span> (<span class="type">Node</span>&lt;K, V&gt; e : table) {
        <span class="keyword">if</span> (e != <span class="keyword">null</span>) {
            <span class="keyword">do</span> {
                <span class="type">Node</span>&lt;K, V&gt; next = e.next;
                <span class="type">int</span> index = indexFor(e.hash, newTable.length);
                e.next = newTable[index];
                newTable[index] = e;
                e = next;
            } <span class="keyword">while</span> (e != <span class="keyword">null</span>);
        }
    }
}</code></pre>
                    </div>

                    <div class="mermaid">
                        graph LR
                            A[元素数量超过阈值] --> B[创建新的数组]
                            B --> C[遍历旧数组]
                            C --> D[重新计算每个元素的位置]
                            D --> E[将元素迁移到新数组]
                            E --> F[更新table引用和阈值]
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="mb-16 bg-gradient-to-br from-indigo-50 to-purple-50 rounded-xl p-8">
            <div class="max-w-4xl mx-auto text-center">
                <h2 class="text-3xl font-bold text-gray-800 mb-6 serif">核心要点总结</h2>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-md">
                        <div class="text-indigo-600 text-3xl mb-4">
                            <i class="fas fa-code-branch"></i>
                        </div>
                        <h3 class="font-semibold text-lg mb-2">哈希表结构</h3>
                        <p class="text-gray-600 text-sm">
                            HashMap 内部使用数组+链表/红黑树的结构，通过哈希算法快速定位元素
                        </p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-md">
                        <div class="text-purple-600 text-3xl mb-4">
                            <i class="fas fa-project-diagram"></i>
                        </div>
                        <h3 class="font-semibold text-lg mb-2">HashSet实现</h3>
                        <p class="text-gray-600 text-sm">
                            HashSet 内部使用 HashMap 实现，元素作为键存储，值为固定对象
                        </p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-md">
                        <div class="text-amber-600 text-3xl mb-4">
                            <i class="fas fa-expand-arrows-alt"></i>
                        </div>
                        <h3 class="font-semibold text-lg mb-2">扩容机制</h3>
                        <p class="text-gray-600 text-sm">
                            当元素数量超过阈值(容量×负载因子)时，哈希表会扩容两倍
                        </p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-semibold mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-150">
                    http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 flex space-x-6">
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```